<!DOCTYPE HTML>
<html th:with="title='编辑营销产品'">
<head th:include="fragments/header :: header">
</head>
<body id="app">
	<div class="page-container">
		<form action="/manager/market/update" method="post" class="form form-horizontal" id="device-form">
			<input type="hidden" name="id" v-model="market.id" />
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					名称：
				</label>
				<div class="formControls col-xs-3 col-sm-3">
					<input type="text" class="input-text size-L" v-model="market.name" id="name" name="name">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					地址：
				</label>
				<div class="formControls col-xs-3 col-sm-3">
					<input type="text" class="input-text size-L" v-model="market.url" id="url" name="url">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					类型：
				</label>
				<div class="formControls col-xs-3 col-sm-3">
					<input type="text" class="input-text size-L" v-model="market.type" id="type" name="type">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					分类：
				</label>
				<div class="formControls col-xs-2 col-sm-2">
					<span class="select-box">
						<select class="select size-L" id="marketClassify" name="marketClassify" v-model="market.marketClassify">
							<option v-bind:value="item" v-for="item in MarketClassify">{{item|marketClassifyFilter}}</option>
						</select>
					</span>
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary size-L radius" type="submit" value="提交">
					<input class="btn btn-primary size-L radius" type="button" onclick="closeWin()" value="关闭">
				</div>
			</div>
		</form>
	</div>

	<!-- <div th:include="fragments/widget :: multuserTreePanel">
</div>
<script th:include="fragments/widget :: multuserTreeJs" type="text/javascript">
</script> -->
	<script type="text/javascript">
		var app = new Vue({
			el : '#app',
			data : {
				MarketClassify : {},
				market : []
			}
		});
		function closeWin() {
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
		$(function() {
			$("#device-form").validate({
				rules : {
					name : {
						required : true,
						minlength : 2,
						maxlength : 16
					},
					url : {
						required : true,
						minlength : 2
					},
					type : {
						required : true,
						minlength : 2,
						maxlength : 8
					}
				},
				onkeyup : false,
				focusCleanup : true,
				success : "valid",
				submitHandler : function(form) {
					var data = $('#device-form').serialize();
					$.ajax({
						type : "POST",
						url : '/manager/market/update',
						data : data,
						beforeSend : function() {

						},
						complete : function() {

						},
						error : function(request) {
							layer.alert("系统出错");
						},
						success : function(data) {
							if (data.status == 0) {
								refreshUParentList();
								layer.alert(data.message, function() {
									var index = parent.layer.getFrameIndex(window.name);
									parent.layer.close(index);
								});
							} else {
								layer.alert(data.message);
							}
						}
					});
				}
			});
		});
		function getIdFromUrl() {
			var addr = location.href;
			var index = addr.lastIndexOf('/') + 1;
			var id = addr.substr(index);
			return id;
		}
		//获取当前营销详情
		function get() {
			var id = getIdFromUrl();
			$.ajax({
				type : "POST",
				url : '/manager/market/get/' + id,
				beforeSend : function() {
				},
				complete : function() {
				},
				error : function(request) {
					alert("Connection error");
				},
				success : function(result) {
					if (result.status == 0) {
						var data = result.data;
						app.market = data;
						for (var i = 0; i < data.device.length; i++) {
							$("#userGroupIds_to").find("option[value='" + data.device[i].id + "']").appendTo($("#userGroupIds"));
						}
					}
				}
			});
		}
		function selectMarketClassify() {
			$.ajax({
				type : "GET",
				url : '/manager/market/selectMarketClassify',
				beforeSend : function() {
				},
				complete : function() {
				},
				error : function(request) {
					alert("Connection error");
				},
				success : function(result) {
					if (result.status == 0) {
						app.MarketClassify = result.data;

					}
				}
			});
		}
		$(function() {
			get();
			selectMarketClassify();
		});
	</script>
</body>
</html>